package com.cskaoyan.day20;

import java.io.*;

public class ThreadJoin {
    public static void main(String[] args) {
        ThreadC threadC = new ThreadC();
        threadC.setName("线程T3");
        threadC.start();
    }
}

class ThreadA extends Thread {

    @Override
    public void run() {

        for (int i = 0; i < 5; i++) {
            System.out.println("我是" + getName() + "，我来！");
        }
    }
}

class ThreadB extends Thread {

    @Override
    public void run() {
        ThreadA threadA = new ThreadA();
        threadA.setName("线程T1");
        threadA.start();
        try {
            threadA.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < 5; i++) {
            System.out.println("我是" + getName() + "，我来！");
        }
    }
}

class ThreadC extends Thread {

    @Override
    public void run() {
        ThreadB threadB = new ThreadB();
        threadB.setName("线程T2");
        threadB.start();
        try {
            threadB.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < 5; i++) {
            System.out.println("我是" + getName() + "，我来！");
        }
    }
}

